package com.gdssoft.framework.dao.system.impl;
/*
 *  捷达世软件(深圳)有限公司 地铁三号线考勤系统
 *  Copyright (C) 2008-2010 ShenZhen JieDaShi Software Limited Company.
*/
import java.util.List;

import org.hibernate.Query;

import com.gdssoft.framework.dao.system.SysConfigDao;
import com.gdssoft.framework.model.system.SysConfig;
import com.gdssoft.core.dao.impl.BaseDaoImpl;

public class SysConfigDaoImpl extends BaseDaoImpl<SysConfig> implements SysConfigDao{

	public SysConfigDaoImpl() {
		super(SysConfig.class);
	}

	@Override
	public SysConfig findByKey(String key) {
		String hql="from SysConfig vo where vo.configKey=?";
		Object[] objs={key};
		List<SysConfig> list=findByHql(hql, objs);
		return (SysConfig)list.get(0);
	}

	@Override
	public List<SysConfig> findConfigByTypeKey(String typeKey) {
		String hql="from SysConfig vo where vo.typeKey=?";
		Object[] objs={typeKey};
		return findByHql(hql, objs);
	}

	@Override
	public List<SysConfig> findTypeKeys() {
		String sql="select vo.typeKey from SysConfig vo group by vo.typeKey";
		return findByHql(sql);
	}
	
	@Override
	public SysConfig findDataValueByTkCkey(String typeKey,String configKey) {
		String hql="from SysConfig vo where vo.typeKey=? and vo.configKey=?";
		Object[] objs={typeKey,configKey};
		List<SysConfig> list=findByHql(hql, objs);
		if(list.size()!=0){
			return (SysConfig)list.get(0);
		}else {
			return null;
		}
		
	}

	@Override
	public void updateDataByKey(String typeKey, String configKey,
			SysConfig sysConfig) {
		String sql = "update SYS_CONFIG set dataValue='"+ sysConfig.getDataValue()+"'" +
					" where configKey='"+ configKey +"'" +
					" and typeKey='"+ typeKey +"'";
		jdbcTemplate.execute(sql);
	}
	
	
}